package com.block.common.security.service.impl.returnData;

import com.alibaba.fastjson.JSONObject;
import com.block.common.constant.AppRspCodeConstant;
import com.block.common.security.service.ReturnDataService;
import com.block.common.vo.ResponseVo;
import com.block.db.entity.AppEncrypt;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 小黑鱼返回参数处理
 */
@Service
public class XHYRespTransferService extends ReturnDataService {

    @Override
    public String dealReturnData(AppEncrypt appEncrypt, ResponseVo returnJson, String version, Date startDate) {
        Date endDate = new Date();
        //计算执行时间
        long costTime=endDate.getTime()-startDate.getTime();
        boolean successFlag=returnJson.getRspCode().equals(AppRspCodeConstant.SUCCESS);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("costTime",costTime);
        jsonObject.put("success",successFlag);
        jsonObject.put("code",successFlag?"200":returnJson.getRspCode());
        jsonObject.put("msg",returnJson.getRspMsg());
        jsonObject.put("data",returnJson.getData()!=null?returnJson.getData():returnJson.getArrayData());
        return jsonObject.toString();
    }
}
